<?php

class Application_Model_DbTable_Complain extends Zend_Db_Table_Abstract
{

    protected $_name = 'complain';
          public function getAll($where=null,$order='admin_id',$method,$page,$number){
        $start = ($page-1)*$number;
        $end = $start+$number;
        $db=$this->getAdapter();
        if($where != null){
            $where='where '.$where;
        }
        $query = "select a.* from (select RowNumber = ROW_NUMBER()
                  OVER (ORDER BY c.$order $method),c.* FROM $this->_name c $where) a
                  where a.RowNumber > $start and a.RowNumber <= $end ";

        $stmt = $db->query($query);
        return $stmt->fetchAll();

    }
    public function countRows($where=null){
        if($where != null){
            $where='where '.$where;
        }
        $sql="select count(*) as total from $this->_name c $where";
        $db=$this->getAdapter();
        $stmt = $db-> query($sql);
        $row = $stmt->fetchAll();
        $stmt->closeCursor();

        return $row[0]['total'];

    }
 

}

